﻿#pragma once
#include "YBaseMuxer.h"

struct AVStream;
/// <summary>
/// 封装器
/// </summary>
class YMuxer :public YBaseMuxer
{

public:
	/// <summary>
	/// 打开封装器
	/// </summary>
	/// <param name="url">输出路径</param>
	/// <returns></returns>
	//AVFormatContext* Open(const char* url);

	//// 打开封装
	AVFormatContext* Open(const char* url,
		AVCodecParameters* video_para = nullptr,
		AVCodecParameters* audio_para = nullptr
	);

	/// <summary>
	/// 写入头部信息
	/// </summary>
	/// <returns></returns>
	bool WriteHead();

	/// <summary>
	/// 写入AVPacket
	/// </summary>
	/// <param name="pkt"></param>
	/// <returns></returns>
	bool Write(AVPacket* pkt);
	/// <summary>
	/// 写入尾部信息
	/// </summary>
	/// <returns></returns>
	bool WriteEnd();
	AVStream* GetVideoStream() {
		return vs_;
	}
	AVStream* GetAudioStream()
	{
		return as_;
	}
	//音视频时间基础
	void set_src_video_time_base(AVRational* tb);
	void set_src_audio_time_base(AVRational* tb);

	YMuxer();
	~YMuxer();
private:
	AVStream* vs_ = nullptr;
	AVStream* as_ = nullptr;

	AVRational* src_video_time_base_ = nullptr;
	AVRational* src_audio_time_base_ = nullptr;

	long long begin_video_pts_ = -1;//原视频开始时间
	long long begin_audio_pts_ = -1;//原音频开始时间
};
